import { Injectable } from '@angular/core';
import { RequestService } from '../../../cores/services';
import { ApiData } from '../../../cores/classes';
import { Observable } from 'rxjs';
import { SearchParams } from '../../../cores/classes/search-params';
import { Goods, GoodsSpecification, GoodsSpecificationDetail } from '../interfaces/manage.interface';
import { Pagination } from 'ng-tui';
@Injectable()
export class SaleService {

    constructor(private request: RequestService) { }

    /**
     * 查询合同，分页
     */
    searchGoods(pagination: Pagination, search: SearchParams): Observable<ApiData> {
        return this.request.get('/managerapi/sale/countract/search', pagination.getpageDataWith(search.values));
    }
    /**
   * 查询报价单，分页
   */
    searchPrice(pagination: Pagination, search: SearchParams): Observable<ApiData> {
        return this.request.get('/managerapi/sale/offer/search', pagination.getpageDataWith(search.values));
    }
    /**
    * 查询等级价格明细，分页
    */
    searchGrade(pagination: Pagination, search: SearchParams): Observable<ApiData> {
        return this.request.get('/managerapi/sale/countract/level/search', pagination.getpageDataWith(search.values));
    }
    /**
    * 查询销售订单列表，分页
    */
    searchOrder(pagination: Pagination, search: SearchParams): Observable<ApiData> {
        return this.request.get('/managerapi/sale/order/search', pagination.getpageDataWith(search.values));
    }
    /**
    * 查询销售订货会列表，分页
    */
    searchMeet(pagination: Pagination, search: SearchParams): Observable<ApiData> {
        return this.request.get('/managerapi/sale/meeting/search', pagination.getpageDataWith(search.values));
    }
    /**
    * 查询销售退单列表，分页
    */
    searchReturn(pagination: Pagination, search: SearchParams): Observable<ApiData> {
        return this.request.get('/managerapi/sale/refund/search', pagination.getpageDataWith(search.values));
    }
    /**
    * 查询专柜要货列表，分页
    */
    searchNeed(pagination: Pagination, search: SearchParams): Observable<ApiData> {
    return this.request.get('/managerapi/sale/counter/order/search', pagination.getpageDataWith(search.values));
    }
    /**
    * 查询专柜退货列表，分页
    */
   searchCounterReturn(pagination: Pagination, search: SearchParams): Observable<ApiData> {
    return this.request.get('/managerapi/sale/counter/refund/search', pagination.getpageDataWith(search.values));
    }
        /**
    * 查询专柜结算单列表，分页
    */
   searchSettlement(pagination: Pagination, search: SearchParams): Observable<ApiData> {
    return this.request.get('/managerapi/sale/counter/settlement/search', pagination.getpageDataWith(search.values));
    }
          /**
    * 查询专柜盘点单列表，分页
    */
   searchInventory(pagination: Pagination, search: SearchParams): Observable<ApiData> {
    return this.request.get('/managerapi/sale/counter/inventory/search', pagination.getpageDataWith(search.values));
    }




    /**
     * 删除销售合同
     */
    deleteGoods(goodsId: number): Observable<ApiData> {
        return this.request.delete(' /managerapi/sale/countract/delete', { goodsId });
    }




    /**
     * 获取指定商品
     */
    getGoods(id: number): Observable<ApiData> {
        return this.request.get('/managerapi/sale/offer/get', { id });
    }
    /**
     * 获取指定合同
     */
    getGood(id: number): Observable<ApiData> {
        return this.request.get('/managerapi/sale/countract/get', { id });
    }
    /**
    * 获取指定销售订单
    */
    getOrderd(id: number): Observable<ApiData> {
        return this.request.get('/managerapi/sale/order/get', { id });
    }
    /**
     * 获取指定订货会详情
     */
    getMeetd(id: number): Observable<ApiData> {
        return this.request.get('/managerapi/sale/meeting/get', { id });
    }
    /**
     * 获取指定订货会详情
     */
    getReturnd(id: number): Observable<ApiData> {
        return this.request.get('/managerapi/sale/refund/get', { id });
    }
    /**
     * 获取指定订货会详情
     */
    getNeed(id: number): Observable<ApiData> {
        return this.request.get('/managerapi/sale/counter/order/get', { id });
    }
    /**
     * 获取指定专柜退货详情
     */
    getCounterReturn(id: number): Observable<ApiData> {
        return this.request.get('/managerapi/sale/counter/refund/get', { id });
    }
        /**
     * 获取指定专柜结算详情
     */
    getSettlement(id: number): Observable<ApiData> {
        return this.request.get('/managerapi/sale/counter/settlement/get', { id });
    }
          /**
     * 获取指定专柜盘点详情
     */
    getInventory(id: number): Observable<ApiData> {
        return this.request.get('/managerapi/sale/counter/inventory/get', { id });
    }





    /**
     * 添加商品
     */
    insertGoods(goods: Goods): Observable<ApiData> {
        return this.request.post(' /managerapi/sale/offer/add', goods);
    }

    /**
     * 更新商品
     */
    updateGoods(goods: Goods) {
        return this.request.put('/store/goods/update', goods);
    }

    /**
     * 更新商品规格
     */
    updateGoodsSpecification(
        goodsId: number,
        goodsSpecifications: GoodsSpecification[],
        goodsSpecificationDetails: GoodsSpecificationDetail[]
    ): Observable<ApiData> {
        return this.request.put('/store/goods/specification/update', { goodsId, goodsSpecifications, goodsSpecificationDetails });
    }

    /**
     * 获取商品下拉选项
     */
    getGoodsTypeOptions(): Observable<ApiData> {
        return this.request.url('/store/goods/type/options');
    }

    /**
     * 上传商品图片
     */
    uploadGoodsImage(file: File): Observable<string> {
        return this.request.ossUpload('/store/goods/image/access', file);
    }

    // getManagerInfo(): Observable<ApiData> {
    //     return this.request.url('/managerapi/info');
    // }

    // updateManagerInfo(manager: Manager): Observable<ApiData> {
    //     return this.request.put('/managerapi/update', manager);
    // }

    // uplodaAvatar(file: File): Observable<string> {
    //     return this.request.ossUpload('/managerapi/avatar/access', file);
    // }
}
